package cn.itcast.utils;

import cn.itcast.pojo.User;

/**
 * @author coolbook
 * @ClassName UserThreadlocal
 * @Description TODO
 * @Date 11:55 2021/11/18
 * @Version 1.0
 */

public class UserThreadlocal {
    public static final ThreadLocal<User> LOCAL = new ThreadLocal<>();
    //私有化构造
    private UserThreadlocal(){

    }
    /**
     * 把对象放到ThreadLocal
     * @param user
     */
    public static void set(User user) {
        LOCAL.set(user);
    }

    /**
     * 返回当前线程中的User对象
     * @return
     */
    public static User get() {
        return LOCAL.get();
    }

    /**
     * 移除当前线程中的User对象
     */
    public static void remove(){
        LOCAL.remove();
    }
}
